package io.kiki.sba.registry.server.clientInterface.remoting.console.handler;

import io.kiki.sba.registry.api.Channel;
import io.kiki.sba.registry.common.model.GenericResponse;
import io.kiki.sba.registry.common.model.Tuple;
import io.kiki.sba.registry.common.model.sessionserver.CheckClientManagerRequest;
import io.kiki.sba.registry.common.model.sessionserver.CheckClientManagerResponse;
import io.kiki.sba.registry.server.clientInterface.client.manager.CheckClientManagerService;
import org.springframework.beans.factory.annotation.Autowired;


public class CheckClientManagerHandler extends AbstractConsoleHandler<CheckClientManagerRequest> {

    @Autowired
    private CheckClientManagerService checkClientManagerService;

    @Override
    public Class interest() {
        return CheckClientManagerRequest.class;
    }

    @Override
    public GenericResponse<CheckClientManagerResponse> doHandle(Channel channel, CheckClientManagerRequest request) {
        Tuple<Boolean, Long> tuple = checkClientManagerService.checkLocalCache(request.getExpectedVersion());
        GenericResponse<CheckClientManagerResponse> response = new GenericResponse();
        response.fillSucceed(new CheckClientManagerResponse(tuple.o1, tuple.o2));
        return response;
    }
}
